<?php
class UserModel{
    protected $username='';
    protected $password='';
    protected $role='';
    protected $id='';
    protected $mapper;
    protected $salt='';
    protected $active='';
    protected $karma='';
    protected $firstname='';
    protected $lastname='';
    protected $age='';
    protected $sex='';
    protected $avatar='';

    public function save(){
        $this->getMapper()->save($this);
        return $this;
    }

    public function edit(){
        $this->getMapper()->edit($this);
        return $this;
    }

    public function delete(){
        $this->getMapper()->delete($this);
        return $this;
    }

    public function find($userId){
        $this->getMapper()->find((int)$userId, $this);
        return $this;
    }

    public function isUser($_username){
        return $this->getMapper()->isUser($_username);
    }

    public function fetchAllLittleUsers(){
        return $this->getMapper()->fetchAllLittleUsers();
        
    }

    public function fetchUsersByFilter($str){
        return $this->getMapper()->fetchUsersByFilter($str);

    }

    public function getCurrentUser(){
        return UserMapper::getCurrentUser($_SESSION['id']);
    }

    public function getCounter(){
        return $this->getMapper()->getCounter();
    }

    public function getUserNews(){
       return $this->getMapper()->getUserNews($this);
    }


//=====================================================================
    public function setUsername($_username){
        $this->username = $_username;
        return $this;
    }
    public function getUsername(){
        return $this->username;
    }

    public function setKarma($_karma){
        $this->karma = $_karma;
        return $this;
    }
    public function getKarma(){
        return $this->karma;
    }

    public function setFirstname($_firstname){
        $this->firstname = $_firstname;
        return $this;
    }
    public function getFirstname(){
        return $this->firstname;
    }

    public function setLastname($_lastname){
        $this->lastname = $_lastname;
        return $this;
    }
    public function getLastname(){
        return $this->lastname;
    }

    public function setAge($_age){
        $this->age = $_age;
        return $this;
    }
    public function getAge(){
        return $this->age;
    }

    public function setSex($_sex){
        $this->sex = $_sex;
        return $this;
    }
    public function getSex(){
        return $this->sex;
    }

    public function setAvatar($_avatar){
        $this->avatar = $_avatar;
        return $this;
    }
    public function getAvatar(){
        return $this->avatar;
    }

    public function setActive($_active){
        $this->active = $_active;
        return $this;
    }
    public function getActive(){
        return $this->active;
    }

    public function setPassword($_password){
        $this->password = $_password;
        return $this;
    }
    public function getPassword(){
        return $this->password;
    }

    public function setId($_id){
        $this->id = $_id;
        return $this;
    }
    public function getId(){
        return $this->id;
    }

    public function setRole($_role){
        $this->role = $_role;
        return $this;
    }
    public function getRole(){
        return $this->role;
    }

    public function setMapper($_mapper){
        $this->mapper = $_mapper;
        return $this;
    }
    public function getMapper(){
        if(!isset($this->mapper)){
            return $this->setMapper(new UserMapper());
        } else {
            return $this->mapper;
        }
    }

    public function setSalt($_salt){
        $this->salt = $_salt;
        return $this;
    }
    public function getSalt(){
        return $this->salt;
    }
}
?>